package ar.edu.utn.frba.tadp.tp.grupo4.fotomultas_ui.controller;

import java.util.List;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.commons.model.ObservableObject;
import org.uqbar.commons.utils.ApplicationContext;
import org.uqbar.commons.utils.Home;

import ar.edu.utn.frba.tadp.tp.grupo4.fotomultas.capturas.Captura;
import ar.edu.utn.frba.tadp.tp.grupo4.fotomultas_ui.ui.AsignacionCapturaManualWindow;
import ar.edu.utn.frba.tadp.tp.grupo4.fotomultas_ui.ui.CreacionCapturaWindow;

public class ListadoConroller extends ObservableObject{
	public static final String CAPTURAS = "capturas";
	public static final String PARENT = "parent";
	public static final String CAPTURA_SELECCIONADA = "capturaSeleccionada";
	public static final String INGRESAR_CAPTURA = "ingresarCaptura";
	public static final String ASIGNAR_CAPTURA = "asignarCaptura";
	
	private WindowOwner parent;
	private Captura captura;
	private final Home<Captura> capturasHome;
	
	public ListadoConroller(Home<Captura> visor) {
		this.capturasHome = visor;
	}
	
	// Acciones
	
	public void ingresarCaptura() {
		new CreacionCapturaWindow(this.parent, ApplicationContext.getInstance().getHome(Captura.class)).open();
		this.firePropertyChange(CAPTURAS, null, this.getCapturas());
	}
	
	public void asignarCaptura(){
		new AsignacionCapturaManualWindow(this.parent, ApplicationContext.getInstance().getHome(Captura.class), this.getCapturaSeleccionada()).open();
		this.firePropertyChange(CAPTURAS, null, this.getCapturas());
	}
	
	// Accesorios
	
	public List<Captura> getCapturas(){
		return this.capturasHome.getObjects();
	}

	public Captura getCapturaSeleccionada(){
		return this.captura;
	}
	
	public void setCapturaSeleccionada(Captura captura){
		this.captura = captura;
	}
	
	public void setParent(WindowOwner parent){
		this.parent = parent;
	}
	
	public WindowOwner getParent(){
		return this.parent;
	}
}
